# -*- coding: utf-8 -*-
'''
Created on 2011-12-25
Google Datastore Models
@author: zivee
'''
from google.appengine.ext import db

class AreaInfo(db.Model):
    '''
    区域信息，包括城市对应 id编码
    '''
    name = db.StringProperty()
    code = db.StringProperty()
    def get_or_put(self):
        query = db.GqlQuery("SELECT __key__ FROM AreaInfo WHERE code = :1", 
                         self.code)
        if query.count():
            akey = query[0]
        else:
            akey = self.put()
            
        return akey
    
class Subscriber(db.Model):
    '''
    保存订阅者信息，包含google账号、邮箱
    '''
    account = db.UserProperty()
    created = db.DateTimeProperty(auto_now_add=True) 
    def get_or_put(self):
        query = db.GqlQuery("SELECT __key__ FROM Subscriber WHERE account = :1", 
                         self.account)
        if query.count():
            akey = query[0]
        else:
            akey = self.put()
            
        return akey       
class ScheduledList(db.Model):
    '''
    天气预报的预定列表
    '''
    area = db.ReferenceProperty(AreaInfo)
    timing = db.TimeProperty() 
    created = db.DateTimeProperty(auto_now_add=True)    
    email = db.EmailProperty()

